<template>
  <div class="date-display">
    <div class="date-display__cur_date"> {{ curDate }}</div>
    <div class="date-display__cur_time"> {{ curTime }}</div>
    <div class="date-display__lunar_date">{{ chinese_date }}</div>
    <div class="date-display__lunar_week">{{ getWeekDay(new Date()) }}</div>
    <div class="date-display__festival">
      <span v-for="(item, index) in festivals.super.concat(festivals.common, festivals.other)" :key="index">
        {{ item }}
      </span>
    </div>
  </div>
</template>

<script>
import {
  ChineseDate
} from "baitu"
import dateUtil from '@/mixins/u-date'

export default {
  name: 'DateDisplay',
  mixins: [dateUtil],
  data() {
    return {
      timer: null,
      curDate: this.dayjs().format("YYYY-MM-DD"),
      curTime: '',
      chinese_date: '',
      festivals: {
        super: [],
        common: [],
        other: []
      },
      isLoading: false
    }
  },
  created() {
    this.convertToChineseDate()
    this.timer = setInterval(() => {
      this.curTime = this.dayjs().format("HH:mm:ss")
    }, 1000)
  },
  methods: {
    async convertToChineseDate() {
      try {
        this.isLoading = true;
        const chineseDate7 = new ChineseDate(new Date());
        const festival = chineseDate7.getFestival();
        this.chinese_date = chineseDate7.toString();
        this.festivals = {
          super: festival.super || [],
          common: festival.common || [],
          other: festival.other || []
        };
      } catch (error) {
        console.error('获取农历日期失败:', error);
        this.festivals = {
          super: [],
          common: [],
          other: []
        };
      } finally {
        this.isLoading = false;
      }
    }
  },
  beforeDestroy() {
    if (this.timer) {
      clearInterval(this.timer);
    }
  }
}
</script>

<style lang="scss" scoped>
@import '@/styles/mixin.scss';

:root {
  --primary-color: #2c3e50;
  --hover-bg: rgba(0, 65, 119, 0.08);
  --active-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --card-radius: 8px;
  --card-padding: 12px;
  --font-mono: 'Courier New', monospace;
}

.date-display {
  @include flex-center;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.98);
  box-sizing: border-box;
  backdrop-filter: blur(4px);
}

.date-display>* {
  line-height: 56px;
  transition: all 0.2s ease;
  padding: 12px;
  border-radius: 6px;
  position: relative;
  overflow: hidden;
}

.date-display>*:hover {
  background: linear-gradient(to right, rgba(153, 190, 236, 0.05), rgba(14, 122, 253, 0.1));
}

/* 通用 hover 效果 */
.date-display__cur_date,
.date-display__cur_time,
.date-display__lunar_date,
.date-display__lunar_week,
.date-display__festival {
  @include flex-column;
  position: relative;
  text-align: center;
  width: 100%;
  cursor: pointer;
  will-change: transform, color, background;
  transition:
    color 0.2s ease,
    transform 0.2s ease,
    background 0.2s ease;
}

.date-display__cur_date,
.date-display__cur_time,
.date-display__lunar_date,
.date-display__lunar_week,
.date-display__festival {
  &::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: currentColor;
    transform: scaleX(0);
    transform-origin: center;
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1;
  }

  &:hover {
    transform: none;
    transition: var(--hover-transition);
    
    &::after {
      transform: scaleX(1);
    }
  }
}

/* 各元素特有样式 */
.date-display__cur_date,
.date-display__cur_time,
.date-display__lunar_date,
.date-display__lunar_week,
.date-display__festival {
  --cur-color: var(--primary-color);
  font-size: 16px;
  font-weight: 500;
  color: var(--cur-color);
  animation:
    slideIn 0.4s cubic-bezier(0.23, 1, 0.32, 1),
    pulse 1.2s ease-in-out 0.4s;

  &:hover {
    --cur-color: #1a73e8;
    
    &::after {
      background: var(--cur-color);
    }
  }
}

.date-display__lunar_date,
.date-display__lunar_week {
  --lunar-color: #666;
  font-size: 15px;
  color: var(--lunar-color);
  opacity: 1;
}

.date-display__lunar_date::after,
.date-display__lunar_week::after {
  background: var(--lunar-color);
}

.date-display__festival {
  --festival-color: #e74c3c;
  --festival-bg: rgba(231, 76, 60, 0.1);
  color: var(--festival-color);
  border-radius: 6px;
  opacity: 1;
  width: 100%;
  white-space: wrap;

  span {
    @include flex-center;
  }
}

.date-display__festival:hover {
  --festival-bg: rgba(231, 76, 60, 0.2);
}

.date-display__festival::after {
  background: var(--festival-color);
}

@keyframes pulse {

  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }

  50% {
    transform: scale(1.01);
    opacity: 0.98;
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-8px);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}
</style>
